package com.lty.zyq.service;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;


@Service
@PropertySource("classpath:custom.properties")
public class TimeService {

    @Value("${over-time.hour}")
    Integer overTimeHour;

    @Value("${over-time.min}")
    Integer overTimeMin;

    @Getter
    @AllArgsConstructor
    public class DateAndWeek{
        String date;
        Integer week;
    }



    DateAndWeek getTodayDateAndWeek() {

        Calendar cal = Calendar.getInstance();
        String today = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH);
        int weak = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return new DateAndWeek(today,weak);
    }

    public Long getRemainTime() {
        Calendar now = Calendar.getInstance();
        Calendar mealTime = getTodayMealTime();
        return mealTime.getTimeInMillis() - now.getTimeInMillis();
    }


    private Calendar getTodayMealTime() {

        Calendar mealTime = Calendar.getInstance();
        mealTime.set(Calendar.HOUR_OF_DAY, overTimeHour);
        mealTime.set(Calendar.MINUTE, overTimeMin);
        mealTime.set(Calendar.SECOND, 0);
        return mealTime;
    }


}
